package com.gis.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author LnnuUser
 * @create 2021-08-27-下午6:36
 */
object Spark22_RDD_Operator_Transform {

  def main(args: Array[String]): Unit = {

    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc: SparkContext = new SparkContext(sparkConf)


    // TODO 算子 --key-value类型
    val rdd1 = sc.makeRDD(List(
      ("a",1),("b",2),("c",3),("d",4)
    ))

    val rdd2 = sc.makeRDD(List(
      ("a",1),("b",2),("c",3)
    ))

    val leftJoinRDD: RDD[(String, (Int, Option[Int]))] = rdd1.leftOuterJoin(rdd2)

    val rightRDD: RDD[(String, (Option[Int], Int))] = rdd1.rightOuterJoin(rdd2)


    leftJoinRDD.collect().foreach(println)
    rightRDD.collect().foreach(println)




    sc.stop()

  }

}
